home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks97
/
KlingonBGApp.sit
/
Klingon BG App
/
Source
/
EventRoutines.c
next >
Wrap
Text File
|
1997-06-28
|
5KB
|
206 lines
// Source code for Klingon Clock. Copyright (C) 1996-1997
// Charles H. Hemstreet IV
//
// Started at MacHack 1996
// Completed at MacHack 1997
//
// Best thanks to:
// My wife Regie, son Chad and baby
// Other thanks to Elden Wood and Bob Clark
//
// This code is distributed "as-is" and implies no warranty or guarantee.
#ifndef __EVENTROUTINES__
#include "EventRoutines.h"
#endif
void DoDeallocateEverything(void)
{
short err;
err = DoRemoveAEHandlers();
}
short DoInstallAEHandlers(void)
{
short err;
err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
NewAEEventHandlerProc(myHandleQUIT), 0 ,false);
err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
NewAEEventHandlerProc(myHandleRUN), 0 ,false);
err = AEInstallEventHandler(kTALKEventClass, kGetTALKEvent,
NewAEEventHandlerProc(myHandleTALK), 0 ,false);
err = AEInstallEventHandler(kTalkFREQEventClass, kGetTalkFREQEvent,
NewAEEventHandlerProc(myHandleTalkFREQ), 0 ,false);
return err;
}
short DoRemoveAEHandlers(void)
{
short err;
err = AERemoveEventHandler(kCoreEventClass, kAEQuitApplication,
NewAEEventHandlerProc(myHandleQUIT) ,false);
err = AERemoveEventHandler(kCoreEventClass, kAEOpenApplication,
NewAEEventHandlerProc(myHandleRUN) ,false);
err = AERemoveEventHandler(kCoreEventClass, kGetTALKEvent,
NewAEEventHandlerProc(myHandleTALK) ,false);
err = AERemoveEventHandler(kCoreEventClass, kGetTalkFREQEvent,
NewAEEventHandlerProc(myHandleTalkFREQ) ,false);
return err;
}
void DoHandleQuitExtension(AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon)
{
gExitNow = true;
}
void DoHandleTalkExtension(AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon)
{
gExitNow = true;
}
void DoHighLevelEventExtension(const EventRecord *er)
{
short err;
err = AEProcessAppleEvent(er);
}
void GrabAndDoEvent(void)
{
EventRecord theEvent;
OSErr myErr = noErr;
if (WaitNextEvent(everyEvent, &theEvent, gSleepTicks, 0L))
{
DispatchEvent(&theEvent);
}
else
{
myErr = DoAllPeriodicProcessing(); // check the clock and tell the time if necessary
assert(myErr == noErr);
}
}
void DispatchEvent( EventRecord *macEvent)
{
if (macEvent->what == 23) // High level event.
{
DoHighLevelEventExtension(macEvent);
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Below this point are support functions for the above routines.
/******************************************************************************
myHandleQUIT
AE Handler for shut down.
******************************************************************************/
pascal OSErr myHandleQUIT(AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon)
{
DoHandleQuitExtension(theAppleEvent, reply, handlerRefcon);
return noErr;
}
/******************************************************************************
myHandleRUN
AE Handler for Open App.
******************************************************************************/
pascal OSErr myHandleRUN(AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon)
{
return noErr;
}
/******************************************************************************
myHandleTALK
AE Handler for clocktalk.
******************************************************************************/
pascal OSErr myHandleTALK(AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon)
{
OSErr myErr = noErr;
myErr = DoAllPeriodicProcessing();
assert(myErr == noErr);
return myErr;
}
/******************************************************************************
myHandleTalkFREQ
AE Handler for the clocks wait between talking...
******************************************************************************/
pascal OSErr myHandleTalkFREQ(AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon)
{
OSErr myErr;
DescType typeCode;
Size sizeOfParam,
actualSize;
long myAEinterval = 1;
myErr = AESizeOfParam( theAppleEvent,
keyDirectObject,
&typeCode,
&sizeOfParam);
if(myErr != noErr){
/*
If we fail here just return the error. We don't need to
do any clean up since we've allocated nothing on the heap
yet. The Apple Event Manager automatically adds the error
number to the reply as keyErrorNumber for non zero handler
returns.
*/
return myErr;
}
myErr = AEGetParamPtr(theAppleEvent, keyDirectObject,
typeLongInteger, &typeCode,
(Ptr)&myAEinterval, sizeof(myAEinterval),
&actualSize);
if(myErr != noErr){
/*
If we fail here just return the error. We don't need to
do any clean up since we've allocated nothing on the heap
yet. The Apple Event Manager automatically adds the error
number to the reply as keyErrorNumber for non zero handler
returns.
*/
return myErr;
}
gSleepTicks = 60*50*myAEinterval; // nothing less than a minute please
myErr = DoAllPeriodicProcessing();
assert(myErr == noErr);
return noErr;
}